/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.util;

import java.io.File;
import java.net.URI;



/**
 *
 * @author Mr.Thanh
 */
public class ServletHelper {
     public static String filter(String input) { 
       StringBuilder filtered = 
                new StringBuilder(input.length()); 
        char c; 
        for (int i = 0; i < input.length(); i++) { 
            c = input.charAt(i); 
            switch (c) { 
                case '<': filtered.append("&lt;");break; 
                case '>': filtered.append("&gt;");break; 
                case '"': filtered.append("&quot;");break; 
                case '&': filtered.append("&amp;"); break; 
                case '\'': filtered.append("&apos;"); break;                 
                default:  filtered.append(c); 
            } 
        } 
        return (filtered.toString()); 
    } 
     
     public static boolean ExistsPath(String path){
         try{
             URI uri = new URI("/"+path);
            File f = new File(uri);
            if(f.exists()){
                  return true;
            }
         }catch(Exception e){}
         
         return false;
     }
     
     public static boolean IsImage(String name){
         try{
             if(name.length()<255 && name.lastIndexOf(".")>0){
             String extension=name.substring(name.lastIndexOf(".")+1);
             String[] extensions={"jpg","png","gif","bitmap","jpeg"};
             for(String ex:extensions){
                 if(extension.equals(ex)){
                     return true;
                 }
             }
         }
         }catch(Exception e){}
         
         return false;
     }
     
     
     
}
